package com.jie.other.compose

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.material.MaterialTheme
import com.jie.other.compose.study03.Study03Page
import com.jie.other.compose.study03.Study03ViewModel

/**
 * Compose学习第3课
 */
class Study03Activity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val taskViewModel by viewModels<Study03ViewModel>()
        setContent {
            MaterialTheme {
                Study03Page(
                    taskList = taskViewModel.mTaskList,
                    onCloseTask = {
                        taskViewModel.removeTask(it)
                    },
                    addTaskClick = {
                        taskViewModel.addTask()
                    },
                    onClearClick = {
                        taskViewModel.clearTask()
                    },
                    backClick = {
                        finish()
                    }
                )
            }
        }
    }
}